package org.syndicate.web;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.syndicate.domain.AmountPie;

@RooWebScaffold(path = "amountpies", formBackingObject = AmountPie.class)
@RequestMapping("/amountpies")
@Controller
public class AmountPieController {
	
	@RequestMapping(method = RequestMethod.POST)
    public String create(@Valid AmountPie amountPie, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
        if (bindingResult.hasErrors()) {
            uiModel.addAttribute("amountPie", amountPie);
            return "amountpies/create";
        }
        uiModel.asMap().clear();
        amountPie.create();
        amountPie.persist();
        return "redirect:/amountpies/" + encodeUrlPathSegment(amountPie.getId().toString(), httpServletRequest);
    }
}
